<template>
  <base-layout
    :visible-sea="false"
    dialog-title="成交"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
    dialogWidth="30%"
  >
    <template #contentPanel>
      <data-table
        :value="tableData.data"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        :width="160"
        :isShowPage="false"
      >
        <template #action="{ row }">
          <i
            class="el-icon-s-check"
            title="成交"

            style="margin-left: 15px; cursor: pointer"
            @click="interestsInfo(row, 0)"
          ></i>
        </template>
      </data-table>
    </template>

    <template #dialog>
      <el-form
        ref="successForm"
        :rules="rules"
        :model="successForm"
        label-width="100px"
      >
        <el-form-item label="身份证" prop="identity">
          <el-input v-model="successForm.identity" placeholder="输入身份证号码">
          </el-input>
        </el-form-item>
        <el-form-item label="所在区域:" prop="province">
          <ProvinceSelect v-model="successForm.province" />
        </el-form-item>

        <el-form-item label="" prop="city">
          <CityCodeSelect
            v-model="successForm.city"
            :province-code="successForm.province"
            class="w-100"
          />
        </el-form-item>

        <el-form-item label="" prop="district">
          <District
            class="w-100"
            :cityCode="successForm.city"
            v-model="successForm.district"
          />
        </el-form-item>
        <el-form-item label="详细地址:" prop="address">
          <el-input
            clearable
            v-model="successForm.address"
            placeholder="详细地址"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer text-center">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="intentionSave('successForm')"
          >确 定</el-button
        >
      </div>
    </template>

    <!-- 




 -->
  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import { indexApis } from '@/api/pre-sale/intentionalCustomer'
import ProvinceSelect from '@/components/ProvinceSelect'
import CityCodeSelect from '@/components/CityCodeSelect'
export default {
  components: {
    ProvinceSelect,
    CityCodeSelect,
  },
  mixins: [
    baseMixin({
      idName: 'id',
      dataName: [''],
      findData: indexApis.intentiongGJFindAll,
    }),
  ],
  data() {
    return {
      rules: {
        identity: [
          {
            required: true,
            message: '请输入身份证',
            trigger: ['blur', 'change'],
          },
        ],
        address: [
          {
            required: true,
            message: '请输入地址',
            trigger: ['blur', 'change'],
          },
        ],
        city: [
          {
            required: true,
            message: '请选择城市',
            trigger: ['blur', 'change'],
          },
        ],
        province: [
          {
            required: true,
            message: '请选择省份',
            trigger: ['blur', 'change'],
          },
        ],
        district: [
          {
            required: true,
            message: '请选择区县',
            trigger: ['blur', 'change'],
          },
        ],
      },
      tableColumnAttributes: [
        { name: '意向车型', value: 'carModelName', type: 'text' },
        { name: '购车预算', value: 'budget', type: 'text' },
        { name: '跟进方式', value: 'mode', type: 'dict', dict: '跟进方式' },
        { name: '销售结果', value: 'result', type: 'dict', dict: '跟进结果' },
        { name: '备注', value: 'remark', type: 'text' },
      ],
      successForm: {
        address: '',
        city: '',
        district: '',
        id: '',
        identity: '',
        province: '',
      },
    }
  },
  created() {
    this.searchOptions = {
      intentionId: this.id,
      type: 2,
    }
  },
  methods: {
     intentionSave(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          await indexApis.intentiongSuccess({
            ...this.successForm,
            id: this.currentRow.id,
          })
          this.setTableData()
          this.dialogVisible = false
        }
      })
    },
    //修改
    interestsInfo(row) {
      this.currentRow = row
      this.handleDataInsert('成交')
    },
  },
}
</script>

<style lang="scss" scoped>
</style>
